package com.jumi.microservice.order.handler;

import com.jumi.microservice.order.context.GoodsSkuContext;
import com.jumi.microservice.order.context.OrderCreateContext;
import com.jumi.microservice.order.context.TransHandlerContext;
import org.springframework.stereotype.Component;

/**
 * @author Dirk
 * @Date 2020-08-04 17:38
 */
@Component
public class ValidateHandler implements TransHandler {

    @Override
    public boolean isAsync() {
        return false;
    }

    @Override
    public boolean handler(TransHandlerContext context) {
        OrderCreateContext ctx = (OrderCreateContext) context;
        for (GoodsSkuContext goodsSkuContext : ctx.getGoodsList()) {
            Integer amount = goodsSkuContext.getGoodsAmount();
            if (amount <= 0 || amount > 100) {
                return false;
            }
        }
        return true;
    }
}